home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / genial / func / input.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-14  |  1.9 KB  |  82 lines

  1. /*
  2.  * input.c -- input routines for GENIAL.  Intimately tied to state_mach.c.
  3.  *
  4.  * This code module maintains dp_stack, a stack of functions which parse a
  5.  * "stream" of input tokens.  Each input token is passed through each function
  6.  * on the stack in turn.  Tokens reach this module through state_dispatch().
  7.  * Functions are added or removed from the queue by dp_push() and
  8.  * dp_del().
  9.  *
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include "display.h"
  14. #include "ui.h"
  15. #include "sm.h"
  16. #include "log.h"
  17. #include "reg.h"
  18.  
  19. #define MAXFUNCS 6
  20.  
  21. static int (*dp_stack[MAXFUNCS]) ();
  22.  
  23. static int dp_size = 0;
  24.  
  25. /* dp_level is used to maintain what level we are at so that dispatch_next()
  26.    works appropriately.  */
  27.  
  28. static int dp_level;
  29.  
  30. dp_push(func)
  31.     int       (*func) ();
  32. {
  33.     if (dp_size == MAXFUNCS) {
  34.     fprintf(stderr, " dp_push: MAXFUNCS exceeded!! \n");
  35.     return -1;
  36.     } else {
  37.     dp_stack[dp_size++] = func;
  38.     }
  39.     return 1;
  40. }
  41.  
  42. dp_del(func)
  43.     int       (*func) ();
  44. {
  45.     /*
  46.      * for now, assume that the func argument refers to the top function on
  47.      * the stack and just pop it off
  48.      */
  49.     if (dp_size > 0)
  50.     dp_stack[--dp_size] = NULL;
  51.     else
  52.     fprintf(stderr, " dp_del: size < 0!! \n");
  53. }
  54.  
  55. /* state_dispatch() is the single entry point for input */
  56. int
  57. state_dispatch(token, arg)
  58.     int       token;        /* token as defined in sm.h */
  59.     caddr_t  *arg;        /* pointer to an optional argument */
  60. {
  61.     /* set dp_level to the top function on the stack */
  62.     dp_level = dp_size;
  63.  
  64.     return dispatch_next(token, arg);
  65. }
  66.  
  67. /* dispatch_next():  call next function on the stack.  Keep track of where we
  68.  are in the stack by use of dp_level */
  69. int
  70. dispatch_next(token, arg)
  71.     int       token;        /* token as defined in sm.h */
  72.     caddr_t  *arg;        /* pointer to an optional argument */
  73. {
  74.     if (dp_level < 0) {
  75.     fprintf(stderr, " dispatch_next: level < 0!! \n");
  76.     return -1;
  77.     } else {
  78.     dp_level--;
  79.     return (*dp_stack[dp_level]) (token, arg);
  80.     }
  81. }
  82.